{% extends "base/base.html" %}

{% comment %}

 Copyright 2013 - Tom Alessi

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and 
 limitations under the License.

{% endcomment %}

{% block content %}

<script type="text/javascript">

   $(function() {

      //Time
      $("#tscan_time").timepicker({
          hourGrid: 4,
          minuteGrid: 10
      });

   });

   // Add Targeted Scan
   $(function() {
      $("#add_scan").click(function () {
        $("#add_scan_div").slideToggle("slow");
      });
    });
   
</script>

<div class="row">
  <div class="large-12 columns">
    {% if tscans %}
    <table>
      <tr>
       <th colspan="8">Targeted Scanner List</th>
      </tr>
      <tr>
        <th>Name</th>
        <th>Host</th>
        <th>Enabled</th>
        <th>Scan Type</th>
        <th>Start Time</th>
        <th>Days</th>
        <th>URL List</th>
        <th>Modify</th>
      </tr>

      {% for row in tscans %}
      <tr>
        <td>{{row.name}}</td>
        <td>{{row.site__site}}</td>
        <td>{{row.scan_enabled__enabled}}</td>
        <td>
          {% if row.scan_method__active %}
          Active
          {% else %}
          Passive
          {% endif %}
        </td>
        <td>{{row.schedule__time|date:"H:i"}}</td>
        <td>
          {% if row.schedule__monday %}M{% endif %}
          {% if row.schedule__tuesday %}T{% endif %}
          {% if row.schedule__wednesday %}W{% endif %}
          {% if row.schedule__thursday %}TH{% endif %}
          {% if row.schedule__friday %}F{% endif %}
          {% if row.schedule__saturday %}S{% endif %}
          {% if row.schedule__sunday %}SU{% endif %}
        </td>
        <td><a href="/adm/tscan_list?id={{row.id}}">URL List</a></td>
        <td><a href="/adm/tscan_modify?id={{row.id}}"><img width="25" height="25" src="/html/images/edit.png"></a></td>
      </tr>
      {% endfor %}
    </table>
    {% else %}
    NO TARGETED SCANS DEFINED - PLEASE DEFINE SOME
    <br><br>
    {% endif %}
  </div>
</div>

<div class="row">
  <div class="spacer_small"></div>
</div>

<div class="row">
  <div class="large-8 columns">
    <a href=# id="add_scan" class="tiny button secondary">Add New Scan</a>
    <br><br>
  </div>
</div>

<div class="row">
  <div id="add_scan_div" class="large-8 columns" {% if not form.errors %}style="display: none;"{% endif %}>
    <form enctype="multipart/form-data" method="POST" action="/adm/tscans/">
      {% csrf_token %}
      <div class="panel radius">

        <div class="row">
          <div class="spacer_small"></div>
        </div>
        
        <div class="row">
          <div class="large-3 columns">Name</div>
          <div class="large-9 columns {% if form.name.errors %}error{% endif %}">
            <input type="text" name="name" value="{% if not form.name.data == None %}{{form.name.data}}{% endif %}" placeholder="Enter a name for this scan" />
            {% if form.name.errors %}
            <small class="error">
              {% for error in form.name.errors %}{{error}}{% endfor %}
            </small>
            {% endif %}
          </div>
        </div>
        
        <div class="row">
          <div class="large-3 columns">Host</div>
          <div class="large-9 columns {% if form.site.errors %}error{% endif %}">
            <input type="text" name="site" value="{% if not form.site.data == None %}{{form.site.data}}{% endif %}" placeholder="Enter the FQDN of the target host (e.g. www.example.com)" />
            {% if form.site.errors %}
            <small class="error">
              {% for error in form.site.errors %}{{error}}{% endfor %}
            </small>
            {% endif %}
          </div>
        </div>
        
        <div class="row">
          <div class="large-3 columns">Scheduled Time</div>
          <div class="large-9 columns {% if form.time.errors %}error{% endif %}">
            <div class="horiz_stack">
              <input type="text" name="time" class="small" id="tscan_time" value="{% if form.time.data %}{{form.time.data}}{% endif %}" placeholder="Enter Time" />
            </div>
            <div class="horiz_stack">
              {{TIME_ZONE}}
            </div>           
            {% if form.time.errors %}
              <small class="error">
                {% for error in form.time.errors %}{{error}}{% endfor %}
              </small>
            {% endif %}
          </div>
        </div>
        
        <div class="row">
          <div class="large-3 columns">Scheduled Day(s)</div>
          <div class="large-9 columns {% if form.monday.errors %}error{% endif %}">
            <div class="horiz_stack">
              <label><input type="checkbox" name="monday" {% if form.monday.data %}checked{% endif %} />&nbsp;M&nbsp;</label>
            </div>
            <div class="horiz_stack">
              <label><input type="checkbox" name="tuesday" {% if form.tuesday.data %}checked{% endif %} />&nbsp;T&nbsp;</label> 
            </div>
            <div class="horiz_stack">
              <label><input type="checkbox" name="wednesday" {% if form.wednesday.data %}checked{% endif %} />&nbsp;W&nbsp;</label>
            </div>
            <div class="horiz_stack">
              <label><input type="checkbox" name="thursday" {% if form.thursday.data %}checked{% endif %} />&nbsp;TH&nbsp;</label> 
            </div>
            <div class="horiz_stack">
              <label><input type="checkbox" name="friday" {% if form.friday.data %}checked{% endif %} />&nbsp;F&nbsp;</label> 
            </div>
            <div class="horiz_stack">
              <label><input type="checkbox" name="saturday" {% if form.saturday.data %}checked{% endif %} />&nbsp;S&nbsp;</label>
            </div>
            <div class="horiz_stack">
              <label><input type="checkbox" name="sunday" {% if form.sunday.data %}checked{% endif %} />&nbsp;SU&nbsp;</label> 
            </div>
           {% if form.monday.errors %}
              <div class="spacer_micro"></div>
              <small class="error">
                {% for error in form.monday.errors %}{{error}}{% endfor %}
              </small>
            {% endif %}
          </div>
        </div>
    
        <div class="row">
          <div class="large-3 columns">Active Scan</div>
          <div class="large-9 columns">
            <input type="checkbox" name="method" {% if form.method.data %}checked{% endif %} />
          </div>
        </div>

        <div class="row">
          <div class="large-3 columns">Scan Enabled</div>
          <div class="large-9 columns">
            <input type="checkbox" name="enabled" {% if form.enabled.data %}checked{% endif %} />
          </div>
        </div>

        <div class="row">
          <div class="large-3 columns">URL List</div>
          <div class="large-9 columns {% if form.list.errors %}error{% endif %}">
            {{form.list}}
            {% if form.list.errors %}
            <small class="error">
              {% for error in form.list.errors %}{{error}}{% endfor %}
            </small>
            {% endif %}          
          </div>
        </div>

        <div class="row">
          <div class="large-3 columns"></div>
          <div class="large-9 columns">
            <input type="submit" class="small button secondary" value="submit"/>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>

{% endblock %}
